/**
 * 产品分类列表
 * 文件命名格式：zmn.模块名称.表名称.功能.jas
 * @author duanzuocai
 * @since 2018/11/12
 */
layui.define(['index', 'form', 'table', 'laypage', 'layedit', 'laydate'], function (exports) {
    var $ = layui.$;
    var form = layui.form;
    var layer = layui.layer;
    var table = layui.table;
    var laypage = layui.laypage;

    var cols = [
        [
            {field: 'sysId', type: 'checkbox', fixed: 'left', width: 50, align: 'center'},
            {field: 'sort', title: '排序号',  fixed: 'left',width: 175, align: 'center', edit: json.hasSort ? 'text' : false, unresize: true, sort: false},
            {field: 'sysId', title: '系统ID',  fixed: 'left',width: 175, align: 'center', unresize: true, sort: false},
            {field: 'sysName', title: '名称', fixed: 'left', width: 175, align: 'center', unresize: true, sort: false},
            {field: 'url', title: '系统链接', width: 175, align: 'center', unresize: true, sort: false},
            {field: 'logoSrc', title: 'logo路径', width: 175, align: 'center', unresize: true, sort: false ,templet:d=>{
                if (d.logoSrc) {
                    return d.logoSrc;
                } else {
                    return "--";
                }
                }},
            {
                field: 'status', title: '状态', width: 175, align: 'center', unresize: true, templet: function (d) {
                    return zmnEnum.STATUS[d.status];
                }
            },
            {field: 'remark', title: '备注', width: 175, align: 'center', unresize: true,templet:d=>{
                    if (d.remark) {
                        return d.remark;
                    } else {
                        return "--";
                    }
                }},
            {field: 'ownerId', title: '责任人ID', width: 175, align: 'center', unresize: true},
            {field: 'owner', title: '责任人', width: 175, align: 'center', unresize: true,templet:d=>{
                    if (d.owner) {
                        return d.owner;
                    } else {
                        return "--";
                    }
                }},

            {field: 'creater', title: '创建人', width: 175, align: 'center', unresize: true,templet:d=>{
                    if (d.creater) {
                        return d.creater;
                    } else {
                        return "--";
                    }
                }},
            {field: 'createTime', title: '创建时间', templet: '#createTime', width: 175, align: 'center', unresize: true,
                templet :function (row){
                    return zmnUtil.createTime(row.createTime);
                }
            }, {field: 'updater', title: '编辑人', width: 175, align: 'center', unresize: true,templet:d=>{
                if (d.updater) {
                    return d.updater;
                } else {
                    return "--";
                }
            }},
            {field: 'updateTime', title: '编辑时间', width: 175, align: 'center', unresize: true,
                templet :function (row){
                    return zmnUtil.createTime(row.createTime);
                }
            }, {
                fixed: 'right', title: '操作', width: 100, align: 'center', templet:
                    '<div>' +
                    (json.hasEdit ? '<a lay-href="/mc/sys/detail.action?sysId={{d.sysId}}" class="layui-btn layui-btn-xs"><i class="layui-icon">&#xe642;</i>编辑</a>' : '') +
                    '</div>'
            }
        ]
    ];
    table.render({
        elem: "#zmn-sys-table",
        toolbar: "#zmn-sys-table-tool",
        title: "分类列表",
        data: json.items,
        limit: json.pageSize,
        cols: cols,
        page: true,
        height: 'full-120'
    });

    laypage.render(zmnPage.laypageOptions(json));

    var ids = new Array();

    // 选择（全选或单选）
    table.on("checkbox(zmn-sys-table)", function () {
        ids = zmnPage.layIdsChecked(json.items, "sysId");
    });

    // 启用/停用
    table.on("toolbar(zmn-sys-table)", function (obj) {
        if (obj.event != "start" && obj.event != "stop") {
            return;
        }
        if (ids.length === 0) {
            return layer.alert("请选择要修改的数据项！");
        }
        zmnPage.layStartStop(obj, "/mc/sys/updateStatus.action", ids.join(","));
    });

    // 修改排序
    table.on("edit(zmn-sys-table)", function (obj) {
        zmnPage.laySort(obj, "/mc/sys/updateSort.action", obj.data.sysId);
    });

    //对外暴露的接口
    exports('art_sys_list', {});
});